package dbManagement;

import java.io.*;
import java.sql.*;
import java.util.*;

import queryPreparation.SAXparseXML;

public class ConnectToDatabase {

	/**
	 * @param args
	 */
	private Connection con = null;
	private Statement st = null;
	private String driverName;
	private String url;
	private String dbUserName;
	private String dbPwd;
	
	public ConnectToDatabase(String dburl, String userName, String password) 
	{
		driverName = "com.mysql.jdbc.Driver";
		url = dburl;
		dbUserName = userName;
		dbPwd = password;
	}
	
	public Statement dbconnect()
    {	
	  try
	  {
		try 
		{
			Class.forName(driverName);
		} catch (ClassNotFoundException e) {
			// TODO Auto-generated catch block
			e.printStackTrace();
		}
		con = DriverManager.getConnection(url, dbUserName, dbPwd);
		st = con.createStatement();
		System.out.println("Connect to database successfully!");
		return st;
	  }
	  catch(SQLException ex){
		System.err.println("Not connect to database!");
		System.out.println("url = " + url );
		ex.printStackTrace();
		return st;
	 }
    }

	public void closeConnect()
	{
		try {
			con.close();
		} catch (SQLException e) {
			e.printStackTrace();
		}
	}

   
}
